<template>
  <div class="main">
    <div class="header flex-h">
      <div @click="goback" class="left">
        <i class="imgIcon"></i>
      </div>
      <h2 class="flex1">升学路径</h2>
      <div class="right" @click="showRouteTypes"></div>
    </div>
    <div v-show="showChoModel" class="modelDiv">
      <div class="choTagArea">
        <div v-for="(item, index) of conditionList" :key="index" :class="['tagItem', choItemArr.indexOf(item.id) !== -1 ? 'hasChoTag' : '']" @click="handleChoCondition(item.id)">{{ item.condition }}</div>
      </div>
      <div class="btnGroup">
        <div class="btn cancel" @click="showChoModel = false">取消</div>
        <div class="btn submit" @click="handleSureChoTag">确定</div>
      </div>
    </div>
    <div class="outDiv">
      <!-- <div class="choTagBox swiper-container" id="activitySwiper">
        <div class="swiper-wrapper">
          <div class="tagList swiper-slide">
            <div v-for="(item, index) of conditionList" :key="index" :class="['tagItem', choItemArr.indexOf(item.id) !== -1 ? 'hasChoTag' : '' ]" @click="handleChoCondition(item.id)">{{ item.condition }}</div>
          </div>
        </div>
      </div> -->
      <scroller>
        <div style="margin-top: 1rem;">
          <ul class="entrancePathList">
            <li class="pathItem" v-for="(item, index) of entrancePathList" :key="index" @click="handleIntoPathDetail(item)">
              <div class="pathImage"><img :src="item.icon" alt="" /></div>
              <div class="pathName">{{ item.pathName }}</div>
            </li>
          </ul>
          <!-- <div class="bottomImage"><img src="~/static/way_pic_banner.png" alt=""></div> -->
        </div>
        <div style="width: 7.5rem;height: 4rem;"></div>
      </scroller>
      <BuyVip :xBuy="showBuyVip" :returnUrl="returnUrl" serverName="升学路径查看详情" @handleCloseBuyDialog="handleCloseBuyDialog"></BuyVip>
    </div>
  </div>
</template>

<script>
// import "swiper/dist/css/swiper.css";
// import Swiper from "swiper/dist/js/swiper.js";
import { queryAllConditions, queryPathByConditions } from '~/api/identity'
import ls from 'store2'
import BuyVip from '~/components/BuyVip'
export default {
  components: {
    // Header,
    BuyVip,
  },
  created() {
    this.commonJs.accectAppParame()
  },
  mounted() {
    this.$visit('SxRouteHome')
    this.$getVip()
    this.returnUrl = '/wx-yxk/#' + this.$route.fullPath
    // this.getAppMsg();
    this.getAllConditionsList()
  },
  data() {
    return {
      conditionList: null, // 筛选条件集合
      entrancePathList: null, // 升学路径集合
      choItemArr: [1],
      showBuyVip: false,
      returnUrl: null,
      canClick: true,
      backApp: true,
      showChoModel: false,
    }
  },
  methods: {
    showRouteTypes() {
      this.showChoModel = true
    },
    handleSureChoTag() {
      this.getPathByConditions()
      this.showChoModel = false
    },
    handleCloseBuyDialog() {
      this.showBuyVip = false
    },
    // activitySwip() {
    //   let mySwiper = new Swiper("#activitySwiper", {
    //     // scrollbar: '.swiper-scrollbar',
    //     // direction: 'vertical',
    //     slidesPerView: "auto",
    //     mousewheelControl: true,
    //     freeMode: true
    //     // roundLengths: true, //防止文字模糊
    //   });
    // },
    // 获取所有筛选条件
    getAllConditionsList() {
      this.$loading('open')
      queryAllConditions().then((res) => {
        this.conditionList = res.data
        this.$nextTick(() => {
          // this.activitySwip()
          this.getPathByConditions()
        })
      })
    },
    checkTerminal() {
      var u = navigator.userAgent
      var chrome = u.match(/Chrome\/([\d.]+)/) || u.match(/CriOS\/([\d.]+)/)
      var isWechat = u.toLowerCase().match(/MicroMessenger/i) == 'micromessenger' || u.match(/_SQ_/i) == '_sq_'
      var isAndroid = u.match(/(Android);?[\s\/]+([\d.]+)?/)
      var isiOS = !chrome && u.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/)
      if (isWechat) {
        return 'wechat'
      } else if (isiOS) {
        return 'ios'
      } else if (isAndroid) {
        return 'android'
      }
    },
    handleChoCondition(id) {
      if (this.canClick) {
        if (this.choItemArr.indexOf(id) == -1) {
          if (id == 1) {
            this.choItemArr = [1]
          } else {
            this.choItemArr.push(id)
            this.choItemArr = this.choItemArr.filter((x) => x !== 1)
          }
        } else {
          this.choItemArr = this.choItemArr.filter((x) => x !== id)
          if (this.choItemArr.length == 0) {
            this.choItemArr = [1]
          }
        }
        // this.getPathByConditions();
      }
    },
    // 通过条件筛选升学路径
    getPathByConditions() {
      this.canClick = false
      this.$loading('open')
      queryPathByConditions({ conditionIds: this.choItemArr })
        .then((res) => {
          this.entrancePathList = res.data
          this.canClick = true
        })
        .catch((err) => {
          this.$vux.toast.text(err.response.data.message)
        })
        .finally(() => {
          this.$hideLoading()
        })
    },
    handleIntoPathDetail(data) {
      let isVipstrs = sessionStorage.getItem('isVipStr')
      if (isVipstrs.indexOf('升学路径') > -1) {
        this.goto('pathDetail', JSON.stringify(data))
      } else {
        this.showBuyVip = true
      }
    },
    goto(routerName, queryData) {
      this.$router.push({
        path: routerName,
        query: {
          type: queryData,
        },
      })
    },
    goback() {
      if (this.backApp) {
        if (this.commonJs.checkTerminal() === 'ios') {
          window.webkit.messageHandlers.backMessage.postMessage('back')
        } else if (this.commonJs.checkTerminal() === 'android') {
          ZMParentsJsToAndroid.backMessage('back')
        } else {
          this.$router.back()
        }
      } else {
        this.$router.back()
      }
    },
  },
}
</script>

<style lang="less" scoped>
.main {
  position: relative;
  .header {
    z-index: 2;
    position: relative;
    width: 100%;
    height: 0.88rem;
    padding: 0 0.32rem;
    background: #fff;
    font-size: 0.3rem;
    letter-spacing: 0.05rem;
    color: #222;
    font-weight: bold;
    .left {
      width: 2rem;
      height: 0.88rem;
    }
    .right {
      width: 2rem;
      height: 0.44rem;
      background: url('~@/static/icon_shaixuan.png') 100% 100% no-repeat;
      background-size: 0.44rem 0.44rem;
    }
    .left {
      .imgIcon {
        width: 0.4rem;
        height: 0.4rem;
        margin-top: 0.22rem;
        display: inline-block;
        background: url('~@/static/sprite/icon_sprites_40.png') -0.1rem -0.1rem;
        background-size: 3rem 2.4rem;
      }
    }
    h2 {
      font-size: 0.36rem;
      font-weight: bold;
      text-align: center;
    }
  }
  .outDiv {
    width: 100%;
    background: #fff;
    height: 100vh;
    // .choTagBox {
    //   width: 100%;
    //   box-sizing: border-box;
    //   background: #fff;
    //   padding-left: 0.32rem;
    //   padding-bottom: 0.2rem;
    //   padding-top: 0.32rem;
    //   margin-bottom: 0.12;
    //   overflow: hidden;
    //   .tagList {
    //     width: auto;
    //     height: 0.8rem;
    //     .tagItem {
    //       min-width: 1.52rem;
    //       height: 0.8rem;
    //       line-height: 0.8rem;
    //       text-align: center;
    //       padding: 0 0.2rem;
    //       border-radius: 0.1rem;
    //       font-size: 0.28rem;
    //       font-weight: normal;
    //       background: #F5F5FA;
    //       margin-right: 0.16rem;
    //       color: #999999;
    //       float: left;
    //     }
    //     .hasChoTag {
    //       background: @mainColor;
    //       color: #fff;
    //       font-weight: bold;
    //     }
    //   }
    // }
    .entrancePathList {
      list-style: none;
      padding: 0 0.32rem;
      margin-bottom: 0.2rem;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      .pathItem {
        width: 2.12rem;
        height: 2.36rem;
        margin-right: 0.24rem;
        margin-bottom: 0.24rem;
        box-shadow: 0 0 0.2rem 0 rgba(204, 204, 204, 0.3);
        border-radius: 0.1rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        .pathImage {
          width: 0.8rem;
          height: 0.8rem;
          margin-top: 0.32rem;
          margin-bottom: 0.24rem;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .pathName {
          color: #222;
          font-size: 0.28rem;
          padding: 0 0.2rem;
          font-weight: bold;
          text-align: center;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
          -webkit-box-orient: vertical;
        }
      }
      .pathItem:nth-child(3n + 0) {
        margin-right: 0;
      }
    }
    //   .bottomImage {
    //     padding: 0 0.32rem;
    //     height: 1.38rem;
    //     width: 100%;
    //     img {
    //       width: 100%;
    //       height: 100%;
    //     }
    //   }
  }
  .modelDiv {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0.88rem;
    left: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 100;
    .choTagArea {
      padding: 0.32rem 0.32rem 0.08rem;
      background: #fff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-wrap: wrap;
      border-bottom: 1px solid #edeef2;
      .tagItem {
        width: 3.27rem;
        height: 0.8rem;
        line-height: 0.8rem;
        border: 1px solid transparent;
        border-radius: 0.06rem;
        text-align: center;
        background: #f7f7fa;
        color: #222;
        font-size: 0.28rem;
        margin-bottom: 0.24rem;
        overflow: hidden;
      }
      .hasChoTag {
        background: #fff;
        border-color: #ffad0d;
        color: #ffad0d;
      }
    }
    .btnGroup {
      width: 100%;
      height: 1.13rem;
      background: #fff;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      padding-right: 0.32rem;
      .btn {
        width: 1.52rem;
        height: 0.64rem;
        border-radius: 0.32rem;
        border: 1px solid #e5e8ed;
        line-height: 0.64rem;
        text-align: center;
        font-size: 0.26rem;
        background: #fff;
        color: #999;
      }
      .cancel {
        opacity: 0.9;
        margin-right: 0.34rem;
      }
      .submit {
        background: #ffa000;
        border-color: transparent;
        color: #fff;
      }
    }
  }
}
</style>
